# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

_name=pycares
pkgname=python-pycares
pkgver=4.3.0
pkgrel=2
pkgdesc='Python interface for c-ares'
arch=('loong64' 'x86_64')
url=https://github.com/saghul/pycares
license=('MIT')
depends=('c-ares' 'python-cffi')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-idna')
optdepends=('python-idna')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz")
sha256sums=('4403d36a57d50ecba55c24d2ceaf2b757d903837c040fc4c05b664fb71922afe')
b2sums=('7d6d1c50647a5d7361f57b6fc4bb6740895a5f5c1ab3caaee409ff01d88b2b83e5fbf9d21ca3153d982904627052e48a45b25edce3184ab86d39fa994aa3d4a4')

build() {
  cd $_name-$pkgver
  PYCARES_USE_SYSTEM_LIB=1 python -m build --wheel --skip-dependency-check --no-isolation
}

# Test failures: gethostbyaddr{,6}, test_getnameinfo
#check() {
#  cd $_name-$pkgver
#  python -m venv --system-site-packages test-env
#  test-env/bin/python -m installer dist/*.whl
#  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python tests/tests.py
#}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_name-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
